﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CECB
{
    /// <summary>
    /// Interaction logic for Project_Window.xaml
    /// </summary>
    public partial class Project_Window : Window
    {
        public Project_Window()
        {
            InitializeComponent();
            combobox_ProjectTeam.ItemsSource = new Dss.Methods.ProjectTeam().getProjectTeams();
        }



        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            DateTime sDate;
            DateTime eDate;


            if (textBox_ProjectName.Text.Length == 0)
            {
                MessageBox.Show("Enter Project Name");
            }
            else if (true)
            {
                try
                {
                    sDate = picker_StartDate.SelectedDate.Value;
                }
                catch (Exception)
                {
                    MessageBox.Show("Select Project Start Date");
                }

            }
            if (true)
            {

                try
                {
                    eDate = picker_EndDate.SelectedDate.Value;
                }
                catch (Exception)
                {
                    MessageBox.Show("Select Project End Date");
                }

            }
            if (textBox_Category.SelectedIndex == -1)
            {
                MessageBox.Show("Select Project Category");
            }
            else if (combobox_ProjectTeam.SelectedIndex == -1)
            {
                MessageBox.Show("Select Project Team");
            }
            else
            {

                String projectName = textBox_ProjectName.Text.Trim();
                sDate = picker_StartDate.SelectedDate.Value;
                eDate = picker_EndDate.SelectedDate.Value;
                String cat = textBox_Category.Text.ToString();
                String teamId = combobox_ProjectTeam.SelectedValue.ToString();

                Dss.Methods.NewProject prj = new Dss.Methods.NewProject();
                bool IsInserted = prj.InsertProject(projectName, sDate, eDate, cat, teamId);
                if (IsInserted == true)
                {

                    MessageBox.Show("Inserted Successfully");
                    clear();
                }
            }



        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        public void clear()
        {
            textBox_ProjectName.Clear();
            textBox_Category.Text = "";
            combobox_ProjectTeam.SelectedIndex = -1;


        }

    }
}
